﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class JobProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<JobEntity> entryList = new List<JobEntity>();

            JobEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new JobEntity();
                    entry.PartNum = item[JobEntity.PART_NUM].ToString();
                    entry.PartDescription = item[JobEntity.PART_DESCRIPTION].ToString();
                    entry.OldPart = item[JobEntity.OLD_PART].ToString();
                    entry.JobNum = item[JobEntity.JOB_NUM].ToString();
                    entry.AssemblySeq = item[JobEntity.ASSEMBLY_SEQ].ToString();
                    entry.WareHouseCode = item[JobEntity.WAREHOUSE_CODE].ToString();
                    entry.OnHandQty = Convert.ToDecimal(item[JobEntity.ON_HAND_QTY].ToString());
                    entry.PartQty = Convert.ToDecimal(item[JobEntity.PART_QTY].ToString());
                    entry.RunQty = Convert.ToDecimal(item[JobEntity.RUN_QTY].ToString());
                    entry.ProdStandard = Convert.ToDecimal(item[JobEntity.PROD_STANDARD].ToString());
                    entry.SetupSize = Convert.ToDecimal(item[JobEntity.SETUP_SIZE].ToString());
                    entry.ProdSize = Convert.ToDecimal(item[JobEntity.PROD_SIZE].ToString());
                    entry.OprSeq = item[JobEntity.OPR_SEQ].ToString();
                    entry.AsmblCommentText = item[JobEntity.ASMBL_COMMENT_TEXT].ToString();
                    entry.OpCode = item[JobEntity.OP_CODE].ToString();
                    entry.OpDesc = item[JobEntity.OP_DESC].ToString();
                    entry.OperPartNum = item[JobEntity.OPER_PARTNUM].ToString();
                    entry.OperOldPart = item[JobEntity.OPER_OLDPART].ToString();

                    entry.LaborHrs = Convert.ToDecimal(item[JobEntity.LABOR_HRS].ToString());
                    entry.LaborQty = Convert.ToDecimal(item[JobEntity.LABOR_QTY].ToString());
                    entry.QtyCompleted = Convert.ToDecimal(item[JobEntity.QTY_COMPLETED].ToString());

                    entry.ReceivedQty = Convert.ToDecimal(item[JobEntity.RECEIVED_QTY].ToString());
                    entry.ResourceGrpID = item[JobEntity.RESOURCE_GRPID].ToString();
                    entry.XPartNum = item[JobEntity.XPART_NUM].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
